<template>
  <div class="app-container">

  <el-alert
    title="API相关配置"
    type="success" 
    closable="false">
  </el-alert><br>

    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="150px">
      <!--
      <el-form-item label="移动端H5地址">
        <el-input v-model="form.site_url" style="width: 370px;" />
      </el-form-item>
      <el-form-item label="uniapp-H5地址">
        <el-input v-model="form.uni_site_url" style="width: 370px;" />
        <span style="color: red">主要用于兼容单独h5</span>
      </el-form-item>
      -->
      
      <el-form-item label="移动端API地址">
        <el-input v-model="form.api_url" style="width: 370px;" />
        <span style="color: red">关联微信支付回调;必须https</span>
      </el-form-item>
      <el-form-item label="后台API地址">
        <el-input v-model="form.admin_api_url" style="width: 370px;" />
      </el-form-item>
      <el-form-item label="核销跳转地址">
        <el-input v-model="form.nucleus_url" style="width: 370px;" />
      </el-form-item>
      <el-form-item label="核销环境">
        <el-radio v-model="form.version_status" :label="0">正式版</el-radio>
        <el-radio v-model="form.version_status" :label="1">体验版</el-radio>
        
      </el-form-item>



      <el-form-item label="文件存储方式">
        <el-radio v-model="form.file_store_mode" :label="1">本地存储</el-radio>
        <!--
        <el-radio v-model="form.file_store_mode" :label="2">云存储</el-radio>
        -->
        
      </el-form-item>

<el-alert
    title="订单相关配置"
    type="success" 
    closable="false">
  </el-alert><br>
  <!--
  <el-form-item label="退/换货收件人">
          <el-input v-model="form.after_user_name" style="width: 370px;" />
        </el-form-item>
        <el-form-item label="退/换货收件人电话">
          <el-input v-model="form.after_phone" style="width: 370px;" />
        </el-form-item>
        <el-form-item label="退/换货收件地址详情">
          <el-input v-model="form.after_address" style="width: 370px;" />
        </el-form-item>
        <el-input type="textarea" v-model="form.user_notice" style="width: 370px;" />
  
        <el-form-item label="使用须知">
         
         <ueditor-wrap v-model="form.user_notice" :config="myConfig" @beforeInit="addCustomDialog"
                            style="width: 600px;" ></ueditor-wrap>
          <span style="color: red">核销订单使用须知</span>
          
        </el-form-item>
-->
        <el-form-item label="订单自动取消">
          <el-input-number v-model="form.make_cancel" style="width: 370px;" />
          <span style="color: red">未支付订单多久后取消订单(分)</span>
        </el-form-item>
        <el-form-item label="订单售后时长">
          <el-input-number v-model="form.after_days" style="width: 370px;" />
          <span style="color: red">确认收货后多久内可申请售后(天)</span>
        </el-form-item>
        <el-form-item label="订单自动确认收货">
          <el-input-number v-model="form.make_hava" style="width: 370px;" />
          <span style="color: red">快递发出后多久自动确认收货(天)</span>
        </el-form-item>

<el-alert
    title="商城相关配置"
    type="success" 
    closable="false">
  </el-alert><br>
        <el-form-item label="商城名称">
          <el-input v-model="form.shop_name" style="width: 370px;" />
        </el-form-item>
        <el-form-item label="联系我们">
          <el-input v-model="form.contact_we" style="width: 370px;" />
        </el-form-item>
        <el-form-item label="ICP备案号">
          <el-input v-model="form.icp_number" style="width: 370px;" />
        </el-form-item>
        
        
        
        
        
        
      

      <!--
        <el-form-item label="包邮金额">
          <el-input v-model="form.store_free_postage" style="width: 370px;" />
          <p style="color: red">如果设置满包邮0 表示全局包邮，如果设置大于0表示满这价格包邮，否则走运费模板算法</p>
        </el-form-item>

        <el-form-item label="隐藏充值按钮">
          <el-radio v-model="form.yshop_show_recharge" :label="0">显示</el-radio>
          <el-radio v-model="form.yshop_show_recharge" :label="1">隐藏</el-radio>
        </el-form-item>
      -->
      


      <el-form-item label="">
        <el-button type="primary" @click="doSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/crud'
import { del, add, get } from '@/api/yxSystemConfig'
import eForm from './form'
import picUpload from '@/components/pic-upload'
import { Message } from 'element-ui'
import UeditorWrap from 'vue-ueditor-wrap'


export default {
  components: { eForm, picUpload,UeditorWrap },
  mixins: [initData],
  data() {
    return {
      delLoading: false,
      form: {
        yshop_show_recharge: 1,
        file_store_mode: 2,
        site_url: '',
        api_url: '',
        uni_site_url: '',
        admin_api_url: '',
        nucleus_url:'',
        version_status:1,
        store_free_postage: '',
        after_address:'',
        make_cancel:30,
        make_hava:7,
        after_days:7,
        icp_number:'',
        contact_we:'',
        after_phone:'',
        after_user_name:'',
        user_notice:''
      },
      myConfig: {
        autoHeightEnabled: false, // 编辑器不自动被内容撑高
        initialFrameHeight: 100, // 初始容器高度
        initialFrameWidth: '600px', // 初始容器宽度
        UEDITOR_HOME_URL: '/UEditor/',
        serverUrl: ''
      },
      rules: {
      }
    }
  },
  created() {
    get().then(rese => {
      const that = this;
      rese.content.map(function(key, value) {
        const keyName = key.menuName
        const newValue = key.value
        if(keyName in that.form){
          that.form[keyName] = newValue
        }
      })

      this.form.file_store_mode = parseInt(this.form.file_store_mode)
      this.form.version_status = parseInt(this.form.version_status)
      this.form.yshop_show_recharge = parseInt(this.form.yshop_show_recharge)
    })
  },
  methods: {
    
    checkPermission,
    doSubmit() {
      add(this.form).then(res => {
        Message({ message: '设置成功', type: 'success' })
      }).catch(err => {
        // this.loading = false
        console.log(err.response.data.message)
      })
    },
    addCustomDialog() {
      window.UE.registerUI('yshop', function (editor, uiName) {
        let dialog = new window.UE.ui.Dialog({
          iframeUrl: '/yshop/materia/index',
          editor: editor,
          name: uiName,
          title: '上传图片',
          cssRules: 'width:1200px;height:500px;padding:20px;'
        });
        this.dialog = dialog;

        var btn = new window.UE.ui.Button({
          name: 'dialog-button',
          title: '上传图片',
          cssRules: `background-image: url(../../../assets/images/icons.png);background-position: -726px -77px;`,
          onclick: function () {
            dialog.render();
            dialog.open();
          }
        });

        return btn;
      }, 37);
    },

  }
}
</script>

<style scoped>

</style>
